home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earcd / phase5 / ppcrelease / examples / msg7.c < prev    next >
C/C++ Source or Header  |  1998-02-21  |  6KB  |  199 lines

  1. /* This test program sends 1000 messages to the PPC and
  2.    shows how long this takes.
  3.    The Messages are send synchron and every msg must
  4.    be replied after another.
  5.    Each Message has a Body with the size of 3747 bytes
  6.    and the PPC side checks if the msg is received correctly.
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/nodes.h>
  11. #include <exec/lists.h>
  12. #include <exec/memory.h>
  13. #include <utility/tagitem.h>
  14. #include <powerup/ppclib/interface.h>
  15. #include <powerup/ppclib/message.h>
  16. #include <powerup/ppclib/tasks.h>
  17. #include <powerup/proto/ppc.h>
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <proto/timer.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include "time.h"
  24. #include "time_protos.h"
  25.  
  26. #define TEXT            "Text sent by M68k processor\n"
  27. #define KILL_ID         0x4b494c4c
  28.  
  29. #define    MSGCOUNT    1000
  30. #define    BODYSIZE    3747
  31.  
  32. struct StartupData
  33. {
  34.     ULONG    MsgCount;
  35. };
  36.  
  37. extern struct Library    *SysBase;
  38.  
  39. int    main(void)
  40. {
  41. struct Library        *PPCLibBase;
  42. struct TagItem        MyTags[10];
  43. void            *PPCPort;
  44. void            *ReplyPort;
  45. void            *StartupMsg;
  46. void            *M68kMsg;
  47. void            *PPCMsg;
  48. void            *ElfObject;
  49. void            *Task;
  50. UBYTE            *Body;
  51. struct StartupData    *StartupData;
  52. void            *MyTimerObject;
  53. ULONG            i,j;
  54.  
  55.   printf("Opening ppc.library\n");
  56.   if (PPCLibBase = OpenLibrary("ppc.library", 44))
  57.   {
  58.     if (MyTimerObject=TimerCreateObject())
  59.     {
  60.       printf("Loading PPC object\n");
  61.       if (ElfObject=PPCLoadObject("PROGDIR:Msg7PPC.elf"))
  62.       {
  63.         printf("Creating reply port\n");
  64.         MyTags[0].ti_Tag    =    TAG_DONE;
  65.         if (ReplyPort = PPCCreatePort(MyTags))
  66.         {
  67.           if (StartupMsg = PPCCreateMessage(ReplyPort, 0))
  68.           {
  69.             printf("Allocating StartupData\n");
  70.             if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
  71.             {
  72.               StartupData->MsgCount    =    MSGCOUNT;
  73.               printf("Creating PPC task\n");
  74.               MyTags[0].ti_Tag    =    PPCTASKTAG_STARTUP_MSG;
  75.               MyTags[0].ti_Data    =(ULONG) StartupMsg;
  76.  
  77.               MyTags[1].ti_Tag    =    PPCTASKTAG_STARTUP_MSGDATA;
  78.               MyTags[1].ti_Data    =(ULONG) StartupData;
  79.  
  80.               MyTags[2].ti_Tag    =    PPCTASKTAG_STARTUP_MSGLENGTH;
  81.               MyTags[2].ti_Data    =    0;
  82.  
  83.               MyTags[3].ti_Tag    =    PPCTASKTAG_STARTUP_MSGID;
  84.               MyTags[3].ti_Data    =    0;
  85.  
  86.               MyTags[4].ti_Tag    =    PPCTASKTAG_MSGPORT;
  87.               MyTags[4].ti_Data    =    TRUE;
  88.  
  89.               MyTags[5].ti_Tag    =    TAG_DONE;
  90.  
  91.               if (Task = PPCCreateTask(ElfObject, MyTags))
  92.               {
  93.                 if (PPCPort=(void*) PPCGetTaskAttrsTags(Task,
  94.                                                         PPCTASKINFOTAG_MSGPORT,0,
  95.                                                         TAG_END))
  96.                 {
  97.                   printf("Allocating memory for message body\n");
  98.                   if (Body = PPCAllocVec(BODYSIZE, MEMF_PUBLIC))
  99.                   {
  100.                     printf("Creating message...\n");
  101.                     if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  102.                     {
  103.                       printf("Sending 1000 SYNCHRON messages with a *Body* and wait for each reply...");
  104.                       TimerSetAttr(MyTimerObject,TIMERTAG_START);
  105.                       for (i=0;i<MSGCOUNT;i++)
  106.                       {
  107.                         for (j=0;j<BODYSIZE;j++)
  108.                         {
  109.                           Body[j]    =    (i+j) & 0xff;
  110.                         }
  111.  
  112.                         PPCSendMessage(PPCPort,
  113.                                        PPCMsg,
  114.                                        Body,
  115.                                        BODYSIZE,
  116.                                        0x12345678);
  117.  
  118.                         PPCWaitPort(ReplyPort);
  119.                         PPCGetMessage(ReplyPort);
  120.                       }
  121.                       TimerSetAttr(MyTimerObject,TIMERTAG_STOP);
  122.                       TimerShow(MyTimerObject);
  123.  
  124.                       printf("Waiting for Task Finish Msg...\n");
  125.                       for (;;)
  126.                       {
  127.                         if ((M68kMsg=PPCGetMessage(ReplyPort)) == StartupMsg)
  128.                         {
  129.                           printf("Ahh..the expected Startup=Finish Msg was received.\nNow we can savely free all resources.\n");
  130.                           break;
  131.                         }
  132.                         else
  133.                         {
  134.                           printf("Some non replied Msg 0x%lx was found..wait\n",
  135.                                  M68kMsg);
  136.                           PPCWaitPort(ReplyPort);
  137.                         }
  138.                       }
  139.  
  140.                       printf("Deleting message...\n");
  141.                       PPCDeleteMessage(PPCMsg);
  142.                     }
  143.                     else
  144.                     {
  145.                       Printf("Could not create Msg\n");
  146.                     }
  147.                     PPCFreeVec(Body);
  148.                   }
  149.                   else
  150.                   {
  151.                     Printf("Could not alloc mem for msg body\n");
  152.                   }
  153.                 }
  154.                 else
  155.                 {
  156.                   Printf("Could not find the PPCTask's msgport\n");
  157.                 }
  158.               }
  159.               else
  160.               {
  161.                 Printf("Could not create PPC task\n");
  162.               }
  163.               PPCFreeVec(StartupData);
  164.             }
  165.             else
  166.             {
  167.               Printf("Could not alloc Startup Data\n");
  168.             }
  169.             PPCDeleteMessage(StartupMsg);
  170.           }
  171.           else
  172.           {
  173.             Printf("Could not create Startup message\n");
  174.           }
  175.           PPCDeletePort(ReplyPort);
  176.         }
  177.         else
  178.         {
  179.           Printf("Could not create reply port\n");
  180.         }
  181.         printf("Unloading PPC object\n");
  182.         PPCUnLoadObject(ElfObject);
  183.       }
  184.       else
  185.       {
  186.         Printf("Could not load the elfobject\n");
  187.       }
  188.       TimerDeleteObject(MyTimerObject);
  189.     }
  190.     printf("Closing ppc.library\n");
  191.     CloseLibrary(PPCLibBase);
  192.   }
  193.   else
  194.   {
  195.     Printf("Could not open ppc.library v44+\n");
  196.   }
  197. }
  198.  
  199.